package tosp;


import java.util.Vector;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;

import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

import tosp.job.Job;
import tosp.job.JobReader;
import tosp.search.LocalSearchAdapter;
import tosp.search.MostCostNeighborSearch;
import tosp.search.RandomNeighborSearch;
import tosp.search.RotateNeigbhborSearch;
import tosp.search.ShakingNeighborSearch;
import tosp.search.ThreeSwitchSearch;
import tosp.search.TwoSwitchSearch;

public class HeuOpBsp1 {

	private Logger log = Logger.getLogger(HeuOpBsp1.class);
	
	static String wd = "bin"; // working dir
	static Vector<Job> j10_to10_0 = null;
	static Vector<Job> j30_to40_0 = null;
	static Vector<Job> j40_to60_0 = null;
	Machine m;
	
	@BeforeClass
	public static void setUpBeforeClass() throws Exception {
		j10_to10_0 = JobReader.fromFile(wd+"/matrices/matrix_10j_10to_NSS_0.txt");
		j30_to40_0 = JobReader.fromFile(wd+"/matrices/matrix_30j_40to_NSS_0.txt");
		j40_to60_0 = JobReader.fromFile(wd+"/matrices/matrix_40j_60to_NSS_0.txt");
	}

	@Before
	public void setUp() throws Exception {
	}

	@After
	public void tearDown() throws Exception {
	}
	
	@Test
	public void Jobs10_Tools10_Inst0_H1() {
		log.info("== Konstruktionsheuristik H1 ==");
		Machine h1=new HistoryMachine(JobSequence.constructSeqGreedy1(j10_to10_0));
		int swh1=h1.calcToolSwitches();
		log.info("c"+h1.getCapacity()+"_j10_to10_0:");
		log.info("Switches= "+swh1);
		log.info("Sequence= "+h1.jobSeq.getSeqAsString());
	}
	
	@Test
	public void Jobs30_Tools40_Inst0_H1() {
		log.info("== Konstruktionsheuristik H1 ==");
		Machine h1=new HistoryMachine(JobSequence.constructSeqGreedy1(j30_to40_0));
		int swh1=h1.calcToolSwitches();
		log.info("c"+h1.getCapacity()+"j30_to40_0: ");
		log.info("Switches= "+swh1);
		log.info("Sequence= "+h1.jobSeq.getSeqAsString());
	}
	
	@Test
	public void Jobs40_Tools60_Inst0_H1() {
		log.info("== Konstruktionsheuristik H1 ==");
		Machine h1=new HistoryMachine(JobSequence.constructSeqGreedy1(j40_to60_0));
		int swh1=h1.calcToolSwitches();
		log.info("c"+h1.getCapacity()+"j40_to60_0: ");
		log.info("Switches= "+swh1);
		log.info("Sequence= "+h1.jobSeq.getSeqAsString());
	}
	
	/**
	 * VND
	 */
	
	@Test
	public void VND40_60() {
		log.info("== VND j40_to60_0 ==");
		HistoryMachine m=Search.variableNeighborhoodDescent(j40_to60_0);
		log.info("Switches="+m.getToolSwitches());
		log.info("Sequence="+m.jobSeq.getSeqAsString());
	}
	
	@Test
	public void VND30_40() {
		log.info("== VND j30_to40_0 ==");
		HistoryMachine m=Search.variableNeighborhoodDescent(j30_to40_0);
		log.info("Switches="+m.getToolSwitches());
		log.info("Sequence="+m.jobSeq.getSeqAsString());
	}
	
	@Test
	public void VND10_10() {
		log.info("== VND j10_to10_0 ==");
		HistoryMachine m=Search.variableNeighborhoodDescent(j10_to10_0);
		log.info("Switches="+m.getToolSwitches());
		log.info("Sequence="+m.jobSeq.getSeqAsString());
	}
	
	/**
	 * GVNS
	 */
	
	@Test
	public void GVNS40_60() {
		log.info("== GVNS j40_to60_0 ==");
		HistoryMachine m=Search.generalVariableNeighborhoodSearch(j40_to60_0,20);
		log.info("Switches="+m.getToolSwitches());
		log.info("Sequence="+m.jobSeq.getSeqAsString());
	}
	
	@Test
	public void GVNS30_40() {
		log.info("== GVNS j30_to40_0 ==");
		HistoryMachine m=Search.generalVariableNeighborhoodSearch(j30_to40_0,20);
		log.info("Switches="+m.getToolSwitches());
		log.info("Sequence="+m.jobSeq.getSeqAsString());
	}
	
	
	@Test
	public void GVNS10_10() {
		log.info("== GVNS j10_to10_0 ==");
		HistoryMachine m=Search.generalVariableNeighborhoodSearch(j10_to10_0,20);
		log.info("Switches="+m.getToolSwitches());
		log.info("Sequence="+m.jobSeq.getSeqAsString());
	}
	
	
	/**
	 * GRASP
	 */
	
	@Test
	public void GRASP10_10() {
		log.info("== GRASP j10_to10_0 ==");
		HistoryMachine m=Search.GRASP(j10_to10_0);
		log.info("Switches="+m.getToolSwitches());
		log.info("Sequence="+m.jobSeq.getSeqAsString());
	}

	@Test
	public void GRASP30_40() {
		log.info("== GRASP j30_to40_0 ==");
		HistoryMachine m=Search.GRASP(j30_to40_0);
		log.info("Switches="+m.getToolSwitches());
		log.info("Sequence="+m.jobSeq.getSeqAsString());
	}
	@Test
	public void GRASP40_60() {
		log.info("== GRASP j40_to60_0 ==");
		HistoryMachine m=Search.GRASP(j40_to60_0);
		log.info("Switches="+m.getToolSwitches());
		log.info("Sequence="+m.jobSeq.getSeqAsString());
	}
	
	/**
	 * GRASP-VNS
	 */
	
	@Test
	public void GRASPVNS40_60() {
		log.info("== GRASPVNS j40_to60_0 ==");
		HistoryMachine m=Search.generalVariableNeighborhoodSearch(j40_to60_0,20);
		log.info("Switches="+m.getToolSwitches());
		log.info("Sequence="+m.jobSeq.getSeqAsString());
	}
	
	@Test
	public void GRASPVNS30_40() {
		log.info("== GRASPVNS j30_to40_0 ==");
		HistoryMachine m=Search.generalVariableNeighborhoodSearch(j30_to40_0,20);
		log.info("Switches="+m.getToolSwitches());
		log.info("Sequence="+m.jobSeq.getSeqAsString());
	}
	
	
	@Test
	public void GRASPVNS10_10() {
		log.info("== GRASPVNS j10_to10_0 ==");
		HistoryMachine m=Search.generalVariableNeighborhoodSearch(j10_to10_0,20);
		log.info("Switches="+m.getToolSwitches());
		log.info("Sequence="+m.jobSeq.getSeqAsString());
	}
	
	
	
}
